package com.gba.mark.exam.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gba.mark.exam.entity.ExamResult;
import com.gba.mark.exam.mapper.ExamReusltMapper;
import com.gba.mark.exam.service.ExamAnswerService;
import com.gba.mark.exam.service.ExamQuestionsService;
import com.gba.mark.exam.service.ExamResultService;
import com.gba.mark.group.service.IGroupService;
import com.gba.mark.user.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ExamResultImpl extends ServiceImpl<ExamReusltMapper, ExamResult> implements ExamResultService {

    @Autowired
    private IUserService userServiceImpl;

    @Resource
    private ExamQuestionsService examQuestionsService;

    @Resource
    private ExamAnswerService examAnswerService;

    @Autowired
    private IGroupService groupService;
    /**
     * 新建并保存一个考试结果
     */

    /**
     * 新建并保存一个考试结果
     */
    //@Override
//    public Integer saveResult(String answer,List<ExamAnswer> user_answer,int user_id,int group_id) {
//        //利用JSONArray中的parseObject方法并指定返回类型来解析json数组字符串answer
//        List<Map<String,String>> list1 = JSONArray.parseObject(answer, List.class);
//
////        System.out.println(list1.size());
//        //计算用户输入的答案与正确答案有几个相符
////        int count = 0;
////        for(int i=0; i<list1.size(); i++){
////            for (int j =0;j<user_answer.size(); j++){
////                if((list1.get(i)).equals(user_answer.get(j))){
////                    count +=1;
////                }
////            }
////        }
//        int count = 0 ;
//        for (int i = 0 ; i<=list1.size(); i++) {
//            if((list1.get(i)).equals(user_answer.get(i))){
//                count +=1;
//            }
//        }
//        //  成绩为答对的题目占整张试卷的百分比
//        int score = (int) ((new BigDecimal((float)count/ list1.size())
//                .setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue())*100);
//          System.out.println(score);
////        String score = "";
////        NumberFormat nf = NumberFormat.getPercentInstance();
////        nf.setMinimumFractionDigits(2);
////        score = nf.format(count/ list1.size());
//
//        //返回ExamResult表
//        ExamResult examResult = new ExamResult();
//
////        //根据user_id和group_name查出group_id
////        Group group = groupService.getOne(new QueryWrapper<Group>().eq("admin_id",admin_id));
////        int group_id = group.getId();
//
//        examResult.setGroupId(group_id);
//        examResult.setUserId(user_id);
//        examResult.setScore(score);
//        return this.baseMapper.insert(examResult);
//    }

    @Override
    public long getScore(String relAnswers, String userAnswers) {
//        JSONObject resJson = (JSONObject)(new JSONParser(relAnswers));
        return 0;
    }

}
